package com.config;

import com.config.dao.EmployeeDao;
import com.config.dao.UserDao;
import com.config.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "com.config")
public class Config {
    /**
     * <h2>方法返回对象将被IoC容器管理，beanId默认为方法名</h2>
     *
     * @return
     */
    @Bean
    public UserDao userDao() {
        return new UserDao();
    }

    @Bean
    /** 依赖注入优先按照对象的ID，如果没有匹配ID则按照类型注入；如果有多个类型的对象，则使用@Primary注解标识 */
    public UserService userService(UserDao userDao, EmployeeDao employeeDao) {
        UserService userService = new UserService();
        userService.setUserDao(userDao);
        userService.setEmployeeDao(employeeDao);
        return userService;
    }
}
